package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.lzpackage.lz_wx.IndexChannel;
import com.cskaoyan.bean.lzpackage.lz_wx.IndexData;
import com.cskaoyan.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @USER: cuiweiguo#
 * @DATE: 2022/5/11
 * @TIME: 3:44
 * @PROJECT_NAME: mallproject2
 */
@RestController
@RequestMapping("wx/home")
public class WxHomeController {
    @Autowired
    AdMapper adMapper;

    @Autowired
    BrandMapper brandMapper;

    @Autowired
    CategoryMapper categoryMapper;

    @Autowired
    CouponMapper couponMapper;

    @Autowired
    GrouponMapper grouponMapper;

    @Autowired
    GoodsMapper goodsMapper;

    @Autowired
    TopicMapper topicMapper;

    @RequestMapping("index")
    public BaseRespVo index() {
        IndexData indexDat = new IndexData();
        //setBanner
        AdExample adExample = new AdExample();
        List<Ad> ads = adMapper.selectByExample(adExample);
        indexDat.setBanner(ads);

        //setBrandList
        BrandExample brandExample = new BrandExample();
        brandExample.setOrderByClause("id desc " + "limit 6");
        List<Brand> brands = brandMapper.selectByExample(brandExample);
        indexDat.setBrandList(brands);

        //setChannel
        List<IndexChannel> channel = categoryMapper.selectIndexData();
        indexDat.setChannel(channel);

        //setCouponList
        CouponExample couponExample = new CouponExample();
        List<Coupon> coupons = couponMapper.selectByExample(couponExample);
        indexDat.setCouponList(coupons);

        //setGrouponList
        GrouponExample grouponExample = new GrouponExample();
        List<Groupon> groupons = grouponMapper.selectByExample(grouponExample);
        indexDat.setGrouponList(groupons);

        //setHotGoodsList
        GoodsExample goodsExample = new GoodsExample();
        GoodsExample.Criteria goodsExampleCriteria = goodsExample.createCriteria();
        goodsExampleCriteria.andIsHotEqualTo(true);
        goodsExample.setOrderByClause("id", "desc" + " limit 4");
        List<Goods> goods = goodsMapper.selectByExample(goodsExample);
        indexDat.setHotGoodsList(goods);

        //setNewGoodsList
        GoodsExample goodsExample1 = new GoodsExample();
        GoodsExample.Criteria goodsExample1Criteria = goodsExample1.createCriteria();
        goodsExample1Criteria.andIsNewEqualTo(true);
        goodsExample1.setOrderByClause("id", "desc" + " limit 4");
        List<Goods> goods1 = goodsMapper.selectByExample(goodsExample1);
        indexDat.setNewGoodsList(goods1);

        //setTopicList
        TopicExample topicExample = new TopicExample();
        topicExample.setOrderByClause("id desc" + " limit 3");
        List<Topic> topics = topicMapper.selectByExample(topicExample);
        indexDat.setTopicList(topics);
        return BaseRespVo.ok(indexDat);
    }
}
